/**
 *
 */
package jp.seraph.cui;

import java.util.List;

/**
 *
 *
 */
public class LsCommand extends AbstractCommand implements Command {
    public LsCommand(Mode aParent, InternalConsole aConsole){
        super(aParent, aConsole);
    }

    /**
     *
     * @see jp.seraph.cui.AbstractCommand#executeImpl(jp.seraph.cui.SystemNode[])
     */
    @Override
    protected void executeImpl(SystemNode[] aArgs, int aArgListIndex) {
        InternalConsole tConsole = getConsole();
        Mode tMode = null;

        if(aArgListIndex == 0)
            tMode =(Mode)aArgs[0];
        else
            tMode = tConsole.getContext().getMode();

        List<SystemNode> tChildren = tMode.getChildren();
        for (SystemNode tSystemNode : tChildren) {
            SystemNodeType tType = tSystemNode.getType();
            String tNodeName = tSystemNode.getName();
            if(tType.isMode())
                tNodeName += "/";
            if(tType.isCommand())
                tNodeName = "*" + tNodeName;
//            if(tType.isData())
//                tNodeName = "-" + tNodeName;

            tConsole.output(tNodeName);
        }
    }

    /**
     *
     * @see jp.seraph.cui.Command#getArgumentTypes()
     */
    public SystemNodeType[][] getArgumentTypes() {
        return new SystemNodeType[][]{
                new SystemNodeType[]{ModeType.getInstance()},
                new SystemNodeType[0]
            };
    }

    /**
     *
     * @see jp.seraph.cui.Command#getHelp()
     */
    public String getHelp() {
        return "ls : show mode-info";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return "ls";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return LsCommandType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }
}
